" Vundle setup.
filetype off
set rtp+=~/.config/nvim/Vundle.vim
call vundle#begin('~/.config/nvim')

" Plugin manager
Plugin 'VundleVim/Vundle.vim'

" Colours
Plugin 'chriskempson/base16-vim'

" Base support for various file types
Plugin 'pangloss/vim-javascript'
Plugin 'elzr/vim-json'
Plugin 'rust-lang/rust.vim'
Plugin 'nvim-treesitter/nvim-treesitter'
Plugin 'neovim/nvim-lspconfig'
Plugin 'lervag/vimtex'

" Convenience
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-speeddating'

" Code analysis/navigation
Plugin 'w0rp/ale'
"Plugin 'ycm-core/YouCompleteMe'

" Autocomplete
Plugin 'Shougo/ddc.vim'
Plugin 'vim-denops/denops.vim'
Plugin 'Shougo/ddc-ui-native'
Plugin 'Shougo/ddc-source-around'
Plugin 'Shougo/ddc-matcher_head'
Plugin 'Shougo/ddc-sorter_rank'

" Diversions
Plugin 'eandrju/cellular-automaton.nvim'

call vundle#end()
filetype plugin indent on

"set clipboard+=autoselect
set clipboard+=unnamed

set background=dark

" Enable base16 swatch-based colour theme.
set termguicolors
"colorscheme base16-black-metal-bathory
"colorscheme base16-atelier-savanna
"colorscheme base16-3024
"colorscheme base16-twilight
"colorscheme base16-eighties
"colorscheme base16-mocha
"colorscheme base16-nord
colorscheme base16-ia-dark

set ruler
set expandtab
set shiftwidth=2

" Spelling
set spelllang=en
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell

" VimTeX config
let g:vimtex_compiler_method = 'tectonic'

" YouCompleteMe config
":noremap <C-_> :YcmCompleter GoTo<CR>
"
"let g:ycm_rust_src_path = '/Users/giles/rust/src'
"let g:ycm_extra_conf_globlist = ['~/firefox/*']
"let g:ycm_extra_conf_globlist = ['~/brave-browser/*', '~/firefox/*']

" DDC (deoplete successor) config
call ddc#custom#patch_global('ui', 'native')
call ddc#custom#patch_global('sources', ['around'])
call ddc#custom#patch_global('sourceOptions', #{
      \ _: #{
      \   matchers: ['matcher_head'],
      \   sorters: ['sorter_rank']},
      \ })
call ddc#custom#patch_global('sourceOptions', #{
      \   around: #{ mark: 'A' },
      \ })
call ddc#custom#patch_global('sourceParams', #{
      \   around: #{ maxSize: 500 },
      \ })
call ddc#custom#patch_filetype(['c', 'cpp'], 'sources',
      \ ['around', 'clangd'])
call ddc#custom#patch_filetype(['c', 'cpp'], 'sourceOptions', #{
      \   clangd: #{ mark: 'C' },
      \ })
"call ddc#custom#patch_filetype('markdown', 'sourceParams', {
"      \   around: #{ maxSize: 100 },
"      \ })

" ddc <TAB> completion.
inoremap <silent><expr> <TAB>
\ pumvisible() ? '<C-n>' :
\ (col('.') <= 1 <Bar><Bar> getline('.')[col('.') - 2] =~# '\s') ?
\ '<TAB>' : ddc#map#manual_complete()

" ddc <S-TAB> completion back.
inoremap <expr><S-TAB>  pumvisible() ? '<C-p>' : '<C-h>'

" ddc enable
call ddc#enable()
